package com.zc.angelica.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zc.angelica.entity.ResponseData;
import com.zc.angelica.mapper.UserInfoMapper;
import com.zc.angelica.entity.UserInfo;
import com.zc.angelica.service.UserInfoService;
import org.springframework.stereotype.Service;

/**
 * 用户信息(UserInfo)表服务实现类
 *
 * @author makejava
 * @since 2022-04-12 23:00:45
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    @Override
    public ResponseData updateUserInfo(UserInfo userInfo) {
        boolean update = this.updateById(userInfo);
        if (update){
            return ResponseData.success("更新成功");
        }
        return ResponseData.error("更新失败");
    }

    @Override
    public Boolean addUserInfo(UserInfo userInfo) {
        return this.save(userInfo);
    }

    @Override
    public ResponseData delUserInfo(Long accountId) {
        QueryWrapper<UserInfo> userInfoQueryWrapper = new QueryWrapper<>();
        userInfoQueryWrapper.eq("account_id",accountId);
        int delete = this.getBaseMapper().delete(userInfoQueryWrapper);
        if (delete==0){
            return ResponseData.error("删除失败");
        }
        return ResponseData.success("删除成功");
    }

    @Override
    public UserInfo getUserInfo(String username) {
        QueryWrapper<UserInfo> userInfoQueryWrapper = new QueryWrapper<>();
        userInfoQueryWrapper.eq("username",username);
        return this.baseMapper.selectOne(userInfoQueryWrapper);
    }
}

